import request from '@/utils/request'
export const getAll = () => {
    return request({
        url: '/api/user/getAll',
        method: 'get'
    })
}

export const getById = (id) => {
    return request({
        url: '/api/user/getById',
        method: 'get',
        params: {
            id
        }
    })
}

export const deleteById = (id) => {
    return request({
        url: `/api/user/deleteById/${id}`,
        method: 'delete',
        params: {
            id
        }
    })
}

export const disableById = (id) => {
    return request({
        url: `/api/user/disableById/${id}`,
        method: 'post',
        params: {
            id
        }
    })
}

export const enableById = (id) => {
    return request({
        url: `/api/user/enableById/${id}`,
        method: 'post',
        params: {
            id
        }
    })
}

export const insertUser = (user) => {
    return request({
        url: '/api/user/insertUser',
        method: 'post',
        data: user
    })
}

export const updateUser = (user) => {
    return request({
        url: '/api/user/updateUser',
        method: 'post',
        data: user
    })
}

export const page = (pageNum, pageSize, userQueryDTO) => {
    // 在发送 GET 请求时，axios 要求查询参数
    //（query parameters）应该是一个扁平的对象，而不是嵌套的对象
    // 将userQueryDTO对象扁平化处理
    const params = { pageNum, pageSize, ...userQueryDTO }

    return request({
        url: '/api/user/page',
        method: 'get',
        params: params
    })
}

export const deleteIds = (ids) => {
    return request({
        url: `/api/user/delete/${ids}`,
        method: 'delete',
        data: ids
    })
}
